package com.learn.thread;

/**
 * 实现多人抢票功能
 * 暴露问题，线程不安全
 */
public class TestThread5 implements Runnable {
    private int ticketNum = 10;

    @Override
    public void run() {
        while (ticketNum > 0) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "------>正在购买第" + ticketNum + "张票");
            ticketNum--;
        }

    }

    public static void main(String[] args) {
        TestThread5 ticketThread = new TestThread5();
        new Thread(ticketThread, "小红").start();
        new Thread(ticketThread, "小明").start();
        new Thread(ticketThread, "黄牛").start();
    }
}
